package com.flowerplus.store.api;


import com.flowerplus.store.common.data.http.HttpCode;
import com.flowerplus.store.common.execption.ApiException;
import com.flowerplus.store.models.result.ResultBean;

import rx.Observable;


/**
 * Created by z on.
 * Des:
 * Date: 2017/6/27
 */

public class ResultCheck {

    public static <T> Observable<T> checkResponse(ResultBean<T> res) {
        if (res.getCode().equals(HttpCode.SUCCESS)) {
            return Observable.just(res.getData());
        }
        return Observable.error(new ApiException(res.getMsg()));
    }

    public static <T> Observable<T> checkResponseCode(ResultBean<T> res) {
        if (res.getCode().equals(HttpCode.SUCCESS)) {
            return Observable.just(res.getData());
        }
        return Observable.error(new ApiException(Integer.valueOf(res.getCode()), res.getMsg()));
    }

}
